package com.wu.controller;/**
 * @author sun
 * @date 2022/3/27 - 22:42
 */

import com.wu.pojo.Images;
import com.wu.service.ImagesService;
import com.wu.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: TODO
 * @author 孙
 * @date 2022/3/27 22:42
 * @version 1.0
 */
@RestController
@Api(tags="Images模块")
@CrossOrigin
@RequestMapping("images")
public class ImagesController {
    @Autowired
    private ImagesService imagesService;
    @PostMapping("/insertImages")
    @ApiOperation(value="增加Images")
    public R insertImages(@RequestBody Images images){
        try {
            imagesService.insertSelective(images);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }

    }


    @GetMapping("/deleteImages/{id}")
    @ApiOperation(value="删除Images")
    public R deleteImages(Integer id){
        try {
            imagesService.deleteByPrimaryKey(id);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @PutMapping("/updateImages")
    @ApiOperation(value="更新Images")
    public R updateImages(@RequestBody Images images){
        try {
            imagesService.updateByPrimaryKeySelective(images);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("/findImages")
    @ApiOperation(value="查询ImagesList")
    public R findImages(Images images){
        try {
            List<Images> list= imagesService.findImages(images);
            return R.ok().data("imagesList",list);
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("/findImagesById/{id}")
    @ApiOperation(value="通过id查询Images")
    public R findImages(Integer id){
        try {
            Images images= imagesService.selectByPrimaryKey(id);
            return R.ok().data("images",images);
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }
}
